using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Framework.Interface;
using UnityEngine;

namespace Framework.Manager
{
    public class ManagerFactory
    {
        private List<IMonoManager> monoManagers = new List<IMonoManager>();
        private List<IManager> managers = new List<IManager>();
        
        public void RegisterManagers()
        {
            managers.Add(EventsManager.Instance);
            managers.Add(HotfixManager.Instance);
            managers.Add(HttpManager.Instance);
            managers.Add(TaskManager.Instance);
            
            monoManagers.Add(NetworkManager.Instance);
            monoManagers.Add(ResourceManager.Instance);
            monoManagers.Add(UIManager.Instance);
        }
        
        public async UniTask InitManagers(Transform parent)
        {
            for (int i = 0; i < managers.Count; i++)
            {
                await managers[i].Initialize();
            }
            
            for (int i = 0; i < monoManagers.Count; i++)
            {
                await monoManagers[i].Initialize(parent);
            }
        }
        
        public void Shutdown()
        {
            
            for (int i = 0; i < monoManagers.Count; i++)
            {
                monoManagers[i].Shutdown();
            }

            for (int i = 0; i < managers.Count; i++)
            {
                managers[i].Shutdown();
            }
        }
    }
}